using System.Collections.Generic;

namespace TLang.Values.Primitives
{
    using Ast;

    public class And : PrimFun
    {

        public And() : base("and", 2)
        {
            
        }


        public override Value Apply(List<Value> args, Node location)
        {

            Value v1 = args[0];
            Value v2 = args[1];
            if (v1 is BoolValue && v2 is BoolValue)
            {
                return new BoolValue(((BoolValue)v1).Value && ((BoolValue)v2).Value);
            }

            Util.Abort(location, "incorrect argument types for and: " + v1 + ", " + v2);
            return null;
        }


        public override Value Typecheck(List<Value> args, Node location)
        {
            Value v1 = args[0];
            Value v2 = args[1];

            if (v1 is BoolType && v2 is BoolType)
            {
                return Type.BOOL;
            }
            Util.Abort(location, "incorrect argument types for and: " + v1 + ", " + v2);
            return null;
        }
    }
}
